<?php
require "common.php";
//$id = $_GET['id'];
//$res = mysql_query("select * from `article` where id = '$id'");
//$res = mysql_fetch_assoc($res);
//if ($_POST){
//    $title=$_POST['title'];
//    $content=$_POST['content'];
//    $time=time();
//    $category_id=$_POST['category_id'];
//    if ($title == "" ||$content == ""){
//        echo "<script>alert('更新失败')</script>";
//    }else{
//        $res = mysql_query("update `article` set `title`= '$title',`content`='$content',`time`='$time',`category_id`='$category_id' where `id` = '$id'");
//        echo "<script>alert('更新成功'),location.href='index.php'</script>";
//    }
//
//}
//$cate = mysql_query("select * from `category`");
//require "templates/edit.html";
class EditController extends CommonController {
    function editPhp(){
        $id = $_GET['id'];
        $article = $this->one("select * from article where id = '$id'");
        $category = $this->all("select * from category");
        if ($_POST){
            $title = $_POST['title'];
            $content = $_POST['content'];
            $time = time();
            $category_id = $_POST['category_id'];
           $res = $this->update("update article set `title`='$title',`content`='$content',`time`='$time',`category_id`='$category_id' where id ='$id'");
            if ($res)
                $this->redirect("编辑成功",'index.php');
            $this->redirect("编辑失败");

        }
//        var_dump($article);
//        exit;
        $this->assign('category',$category);
        $this->assign('article',$article);
        $this->display('edit.html');
    }
}
$edit = new EditController;
$edit->editPhp();


